package com.sihan.swvp.action.sys;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sihan.swvp.action.BaseAction;
import com.sihan.swvp.service.sys.PrivEnterpriseService;
@Controller
@RequestMapping("/priv/enterprise")
public class PrivEnterpriseAction extends BaseAction{
	@Autowired
	PrivEnterpriseService privEnterpriseService;
	
	
	
	
	@ResponseBody
	@RequestMapping(value="/getEnterprise")
	public List<Map<String, Object>> getEnterprise(){
		
		return privEnterpriseService.getEnterprise(getLoginUser());
	}
	
	@ResponseBody
	@RequestMapping(value="/getPri")
	public List<Map<String, Object>> getPri(@RequestParam("e")int e){
		
		return privEnterpriseService.getPri(e);
	}
	
	@ResponseBody
	@RequestMapping(value="/addPri")
	public Object addPri(@RequestParam("e")int e,@RequestParam("pries")String pries){
		try {
			String[] idsarray = pries.split(",");
			privEnterpriseService.deleteAllPriv(e);
			if(pries.length() > 0){
				Map<String,Object> params = new HashMap<String,Object>();
				params.put("e", e);
				params.put("pries", idsarray);
				privEnterpriseService.addPrivs(e,idsarray);
			}
			
			return successMsg("");
		} catch (Exception ex) {
			// TODO: handle exception
			return failMsg("服务器异常");
		}
//		privEnterpriseService.addPri(e, prie);
	}
	
	@ResponseBody
	@RequestMapping(value="/deletePri")
	public void deletePri(@RequestParam("e")int e,@RequestParam("prie")int prie){
		
//		privEnterpriseService.deletePri(e, prie);
	}
	
}
